package com.iran.singleton;

/**
 * 只有当instance为null时，需要获取同步锁，创建一次实例。当实例被创建，则无需试图加锁。
 */
public class SingletonSynClass {
    private static SingletonSynClass singletonSynClass = null;
    private SingletonSynClass() {
    }
    public static SingletonSynClass getInstance(){
        if (singletonSynClass == null){
            synchronized (SingletonSynClass.class){
                if (singletonSynClass == null){
                    singletonSynClass = new SingletonSynClass();
                }
            }
        }
        return singletonSynClass;
    }
}
